/**
 * Created by zhoucl on 2015/9/11.
 */
function initConfig(cid, rs, ipcc, cidarray,val){
    var cidDom = $('#'+ cid);
    var rsDom = $('#' + rs);
    var ipccDom = $('#' + ipcc);

    for(var i = 0; i < cid_array.length; i++) {
        if(cid_array[i] == undefined) continue;

        if(cid_array[i].indexOf('|') >= 0) {
            var arr = cid_array[i].split('|');
            if(val == arr[0] ){
            	cidDom.append('<option value="' + arr[0] + '" data="' + i + '" selected>' + arr[1] + '</option>');
            } else {
            	cidDom.append('<option value="' + arr[0] + '" data="' + i + '">' + arr[1] + '</option>');
            }
        } else {
            cidDom.append('<option value="' + i + '">' + cidarray[i] + '</option>');
        }

    }

    rsDom.html('<option value="">请选择</option>');
    ipccDom.html('<option value="">请选择</option>');
}

function changeCid(obj, rs, ipcc, dsarray,val) {
    var rsDom = $('#' + rs);
    var ipccDom = $('#' + ipcc);
    var id = $(obj).find('option:selected').attr('data');
    var flag = true;
    for(var i = 0; i < dsarray.length; i++) {
        if(dsarray[i] == undefined) continue;

        if(i == id) {
            rsDom.html('');
            for(var j = 0; j < dsarray[i].length; j++) {
                if(dsarray[i][j] == undefined) continue;
                flag = false;
                
                if(dsarray[i][j].indexOf('|') >= 0) {
                	var arr = dsarray[i][j].split('|');
                	if(val == arr[0]) {
                		rsDom.append('<option value="' + arr[0] + '" data="' + j + '" selected>' + arr[1] + '</option>');
                	} else {
                		rsDom.append('<option value="' + arr[0] + '" data="' + j + '">' + arr[1] + '</option>');
                	}
                } else {
                	rsDom.append('<option value="' + dsarray[i][j] + '">' + dsarray[i][j] + '</option>')
                }
            }
        }
    }

    ipccDom.html('');
    ipccDom.html('<option value="">请选择</option>');

    if(flag) {
        rsDom.html('');
        rsDom.html('<option value="">请选择</option>');
    }
}

function changeRs(obj, ipcc, ipccarray,val) {
    var ipccDom = $('#' + ipcc);
    var id = $(obj).find('option:selected').attr('data');
    var flag = true;
    for(var i = 1000; i < ipccarray.length; i++) {
        if(ipccarray[i] == undefined) continue;

        if(i == id) {
            ipccDom.html('');

            for(var j = i * 100; j < ipccarray[i].length; j++) {
                if(ipccarray[i][j] == undefined) continue;

                flag = false;
                if(ipccarray[i][j].indexOf('|') >= 0) {
                    var arr = ipccarray[i][j].split('|');
                    if(val == arr[0]){
                    	ipccDom.append('<option value="' + arr[0] + '" selected>' + arr[1] + '</option>')
                    } else {
                    	ipccDom.append('<option value="' + arr[0] + '">' + arr[1] + '</option>')
                    }
                } else {
                    ipccDom.append('<option value="' + ipccarray[i][j] + '">' + ipccarray[i][j] + '</option>')
                }
            }
        }
    }

    if(flag) {
        ipccDom.html('');
        ipccDom.html('<option value="">请选择</option>');
    }
}